import java.util.Comparator;
import java.util.PriorityQueue;

//重写一个比较器方法
class Clmp implements Comparator<Integer>{

    @Override
    public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);
    }
}










public class Test {
    /*public static void main(String[] args) {
          int [] array = {27,15,19,18,28,34,65,49,25,37};
          TestHeap testHeap = new TestHeap();
        for (int i = 0; i < array.length; i++) {
              testHeap.push(array[i]);
        }
    }*/


    public int[] smallestK(int[] arr, int k) {
        PriorityQueue<Integer>priorityQueue = new PriorityQueue<>(new Clmp());
        //我们需要创建一个大根堆
        //将前k个元素插入到优先级队列中去
        for (int i = 0; i < k; i++) {
             priorityQueue.offer(arr[i]);
        }
        //然后遍历剩余的元素
        for (int i = k; i <arr.length ; i++) {
               if(arr[i]< priorityQueue.peek()) {
                   //则将两者的值进行交换
                   priorityQueue.poll();
                   priorityQueue.offer(arr[i]);
               }
        }
        int [] ret = new int[k];
        for (int i = 0; i < k; i++) {
             ret[i]  = priorityQueue.poll();
        }
        return ret;



    }

    public static void main1(String[] args) {
        PriorityQueue<Integer>priorityQueue = new PriorityQueue<>();
        //我们需要创建一个大根堆,这是小根堆
        priorityQueue.offer(11);
        priorityQueue.offer(12);
        System.out.println(priorityQueue.peek());
    }

    public static void main(String[] args) {
        for (int i = 10; i <2 ; i++) {
            System.out.println(1);
        }
    }

}
